package com.example.mapdata.config;

import com.example.mapdata.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override // 注册拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        // 拦截所有请求，通过判断用户是否登录来决定是否需要登录
        // addPathPatterns 代表要拦截的路径
        // excludePathPatterns 代表要排除的路径
        registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns("/**/user/**","/**/register");
    }
}
